$(function () {

    dayStyleTxtFn();
    checkAgentUser();

    $("body").on('click','.myCourse',function () {//我的课程
        window.location.href = baseloaction + '/mobile/uc/course/myCourse';
    }).on('click','.myStudyRecord',function () {//学习记录
        window.location.href = baseloaction + '/mobile/uc/course/play/record/userStudyRecord';
    }).on('click','.myExam',function () {//考试
        window.location.href = baseloaction + '/mobile/uc/exam/record/history'
    }).on('click','.myQa',function () {//我的问答
        window.location.href = baseloaction + '/mobile/uc/qa/toMyQuestionView';
    }).on('click','.myOrder',function () {//我的订单
        window.location.href = baseloaction + '/mobile/uc/order/orderList';
    }).on('click','.mySettings',function () {//设置
        window.location.href = baseloaction + '/mobile/uc/systemSet';
    }).on('click','.myFeedback',function () {//反馈
        window.location.href = baseloaction + '/mobile/uc/op/feedback/feedbackIndex';
    }).on('click','.myExtension',function () {//推广
        var agentCenterSwitch = $('#agentCenterSwitch').val();
        if(agentCenterSwitch=="OFF"){
            Zepto.alert("提示</br>推广中心已关闭，请后续关注...");
        }else{
            $.ajax({
                url: baseloaction + '/mobile/uc/agent/checkAgentUser',
                type: 'post',
                dataType: 'json',
                success: function (result) {
                    if(result.entity == 1){
                        window.location.href = baseloaction + '/mobile/uc/agent/toOpenExtensionView';
                    }else if(result.entity == 2){
                        window.location.href = baseloaction + '/mobile/uc/agent/agentUserInfo';
                    }else if(result.entity == 3){
                        $.toast(result.message);
                    }else {
                        $.confirm(result.message,'',function () {
                            window.location.href = baseloaction + '/mobile/uc/agent/toOpenExtensionView';
                        });
                    }
                },
                error: function (error) {
                    $.toast('系统繁忙，请稍后重试');
                }
            })
        }
    }).on('click','.myMessage',function () {//消息
        window.location.href = baseloaction + '/mobile/uc/op/affiche/queryUserAfficheList';
    }).on('click','.myGiftCardAndCoupon',function () {//优惠券和礼卡
        window.location.href = baseloaction + '/mobile/uc/op/coupon/myCoupons';
    }).on('click','.myAccount',function () {
        window.location.href = baseloaction + '/mobile/uc/account/myAccount';
    }).on('click','.myMember',function () {
        window.location.href = baseloaction + '/mobile/uc/member/myMember';
    }).on('click','.myTopic',function () {
        window.location.href = baseloaction + '/mobile/uc/topic/myTopic';
    }).on('click','.myDownload',function () {
        window.location.href = appHrefDown;
    }).on('click','.myIntegral',function(){
        window.location.href = baseloaction + '/mobile/uc/integral/integralIndex';
    }).on('click','.myTask',function(){
        window.location.href = baseloaction + '/mobile/uc/operation/operationIndex';
    }).on('click','#iconkecheng',function(){//跳转到学习中心
        SetCookie("jumpUrl",'/mobile/uc/learningCenter');
        window.location.href = baseloaction + '/mobile/uc/learningCenter';
    }).on('click','#iconjilu',function(){//跳转到直播课表
        SetCookie("jumpUrl",'/mobile/uc/index');
        window.location.href = baseloaction + '/mobile/uc/classSchedule';
    });

    //加载用户是不是推广员
    function checkAgentUser() {
        $.ajax({
            url: baseloaction + '/mobile/uc/agent/checkAgentUser',
            type: 'post',
            dataType: 'json',
            success: function (result) {
                if(result.entity == 1){
                    $("#open").removeClass('hide');
                }
            }
        })
    }

    //获取一天中的不同时间段
    function dayStyleTxtFn() {
        var _date = new Date();
        var _hours = _date.getHours(),
            _txt = '';
        if (_hours >= 3 && _hours < 6) {
            _txt = '深夜了，注意休息，劳逸结合更有效率';
        } else if (_hours >= 6 && _hours < 8) {
            _txt = '早晨好，一天之计在于晨，快来学习吧';
        } else if (_hours >= 8 && _hours < 11) {
            _txt = '上午好，欢迎来到学习中心，开启学习之旅';
        } else if (_hours >= 11 && _hours < 13) {
            _txt = '中午好，午饭吃好吃多，才有力气学习哟';
        } else if (_hours >= 13 && _hours < 17) {
            _txt = '下午好，小憩一下，轻松开启学习之旅';
        } else if (_hours >= 17 && _hours < 19) {
            _txt = '傍晚好，站起来，走一走，休息一下再学习';
        } else if (_hours >= 19 && _hours < 23) {
            _txt = '晚上好，少食多餐，为大脑提供充分的学习空间';
        } else if (_hours >= 23 && _hours < 3) {
            _txt = '深夜了，注意休息，劳逸结合学习更有效率';
        }
        $('#dayStyleTxt').empty().html(_txt)
    }

    //禁止ios浏览器页面上下滚动 (橡皮筋效果)
    iosTrouchFn(document.querySelector('.native-scroll'))

    //获取可领取的优惠券列表
    $.getReceiveCouponList();

    showWxPblice();
    
    //展示微信官方公众号二维码
    function showWxPblice() {
        var _ele = '<div class="text-center"><img src="'+wechatServiceUrl+'" width="240" height="240" /><section><span class="c-888 fs6">关注官方微信公众号</span></section></div>'
        $(document).on('click', '#showWxPblice', function () {
            $.confirm(_ele, '',function (em) {});
            $('.modal-in').find('.modal-button').text('关闭').css('color', '#bbb');
            $('.modal-in').find('.modal-button-bold').remove();
        })
    }

        getMagNum();
        function getMagNum(){
        Zepto.ajax({
            url: baseloaction + '/mobile/uc/op/affiche/countReceiveAffiche',
            type: 'post',
            success: function (response) {
                if (response.success) {
                    var count = response.entity;
                    if (count&&count!=0) {
                        Zepto('#unread-message-count').text(count).removeClass('hide');
                    } else {
                        Zepto('#unread-message-count').addClass('hide');
                    }
                }
            },
            error: function () {
                Zepto('#unread-message-count').addClass('hide');
            }
        });
    }
});